package com.qyhl.module_home.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qyhl.module_home.R;
import com.qyhl.webtv.basiclib.utils.StringUtils;
import com.qyhl.webtv.commonlib.entity.home.HomeBean;
import com.qyhl.webtv.commonlib.utils.config.HomeThemeColorUtil;

import java.util.List;

/**
 * Created by Cookie on 2017/1/16.
 */

public class MyGridViewAdapter extends BaseAdapter {
    Context context;
    List<HomeBean.SecMenus> list;

    public MyGridViewAdapter(Context context, List<HomeBean.SecMenus> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder vh;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.home_item_home_fragment_navigation, null);
            vh = new ViewHolder();
            vh.tv = (TextView) view.findViewById(R.id.title);
            vh.iv = (ImageView) view.findViewById(R.id.icon);
            vh.tv.setTextColor(HomeThemeColorUtil.getTabNormalColor());
            view.setTag(vh);
        } else {
            vh = (ViewHolder) view.getTag();
        }
        if (StringUtils.isEmpty(list.get(position).getMenuName())) {
            vh.tv.setVisibility(View.GONE);
        } else {
            vh.tv.setText(list.get(position).getMenuName());
            vh.tv.setVisibility(View.VISIBLE);
        }

        if (StringUtils.isEmpty(list.get(position).getMenuImg())) {
            vh.iv.setVisibility(View.GONE);
            vh.tv.setTextSize(15);
        } else {
            vh.tv.setTextSize(11);
            vh.iv.setVisibility(View.VISIBLE);
            Glide.with(context)
                    .load(list.get(position).getMenuImg())
                    .into(vh.iv);
        }
        return view;
    }

    class ViewHolder {
        TextView tv;
        ImageView iv;
    }
}
